package com.jeeplus.modules.web.service;

import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.web.entity.YjQrcodes;
import com.jeeplus.modules.web.mapper.YjQrcodesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 二维码Service
 * @author liangbing
 * @version 2021-03-14
 */
@Service
@Transactional(readOnly = true)
public class YjQrcodesService extends CrudService<YjQrcodesMapper, YjQrcodes> {
    @Autowired
    private YjQrcodesMapper yjQrcodesMapper;

    public YjQrcodes get(String id) {
        return super.get(id);
    }

    public Long count(YjQrcodes yjQrcodes) {
        return yjQrcodesMapper.count(yjQrcodes);
    }

    public boolean isInUse(List<String> ids) {
        return yjQrcodesMapper.getInUseCount(ids, DataEntity.DEL_FLAG_NORMAL) > 0;
    }

    public List<YjQrcodes> findList(YjQrcodes yjQrcodes) {
        return super.findList(yjQrcodes);
    }

    public Page<YjQrcodes> findPage(Page<YjQrcodes> page, YjQrcodes yjQrcodes) {
        return super.findPage(page, yjQrcodes);
    }

    @Transactional(readOnly = false)
    public void save(YjQrcodes yjQrcodes) {
        super.save(yjQrcodes);
    }

    @Transactional(readOnly = false)
    public void delete(YjQrcodes yjQrcodes) {
        super.delete(yjQrcodes);
    }

    /**
     * 批量生成二维码
     * @param qrcodesList 二维码列表
     * @return
     */
    @Transactional(readOnly = false)
    public int batchCreateQrcode(List<YjQrcodes> qrcodesList){
        return yjQrcodesMapper.batchCreateQrcode(qrcodesList);
    }

    /**
     * 获得未生成过图片的二维码列表
     * @return
     */
    public List<YjQrcodes> fetchNoImageQrCodes() {
        return yjQrcodesMapper.fetchNoImageQrCodes(DataEntity.DEL_FLAG_NORMAL);
    }

    /**
     * 以ids列表获取相对应的二维码列表
     * @param idsList
     * @return
     */
    public List<YjQrcodes> getQrCodesByIds(List<String> idsList) {
        return yjQrcodesMapper.getQrCodesByIds(idsList);
    }

}
